package com.yyy.dm.consumer.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yyy.dm.CommonResponse;
import com.yyy.dm.VoUtil;
import com.yyy.dm.dao.SchedulerSeatPriceMapper;
import com.yyy.dm.scheduler.DmSchedulerSeatPrice;
import com.yyy.dm.scheduler.SeatPriceDTO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class SchedulerSeatPriceConsumerService {
    @Resource
    private SchedulerSeatPriceMapper schedulerSeatPriceMapper;

    public CommonResponse getPrice(Long scheduleId){
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("scheduleId",scheduleId);
        List<DmSchedulerSeatPrice> schedulerSeatPriceList = schedulerSeatPriceMapper.selectList(queryWrapper);
        List<SeatPriceDTO> seatPriceDTOList = new ArrayList<>();
        for (DmSchedulerSeatPrice dmSchedulerSeatPrice : schedulerSeatPriceList) {
            SeatPriceDTO seatPriceDTO = new SeatPriceDTO();
            BeanUtils.copyProperties(dmSchedulerSeatPrice,seatPriceDTO);
            seatPriceDTO.setIsHaveSeat(dmSchedulerSeatPrice.getSeatNum()>0?1:0);
            seatPriceDTOList.add(seatPriceDTO);
        }
        return VoUtil.returnSuccess(seatPriceDTOList);
    }
}
